package com.wuhuiyue.controller;


import com.wuhuiyue.entity.Result;
import com.wuhuiyue.entity.Software;
import com.wuhuiyue.service.ISoftwareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hy-woo
 * @since 2022-06-11
 */
@RestController
@RequestMapping("/software")
public class SoftwareController {

    @Autowired
    ISoftwareService softwareService;

    @RequestMapping("/delete")
    public Result delete(int id){
        boolean b = softwareService.removeById(id);
        return b?Result.OK():Result.failed(201,"no");
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Software software){
        boolean b = softwareService.updateById(software);
        return b?Result.OK():Result.failed(201,"no");
    }

    @RequestMapping("/getSoftware")
    public Result getSoftware(int id){
        Software software = softwareService.getById(id);
        return Result.OK(software);
    }

    @RequestMapping("/save")
    public Result save(@RequestBody Software software){
        software.setCreated(new Date());
        boolean b = softwareService.saveOrUpdate(software);
        return b?Result.OK():Result.failed(201,"no");
    }

}
